﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace XiaoYuStockAnalysis.Core.Entities
{

    /// <summary>
    /// http://finance.ifeng.com/app/hq/stock/sz002109/
    /// </summary>
    public class TradeExtensionsHelper
    {


        
        /// <summary>
        /// 返回股票数据
        /// </summary>
        /// <param name="sharesCode"></param>
        /// <returns></returns>
        public static TradeExtensionsData LoadTransferData(string sharesCode)
        {
            string url = string.Format("http://finance.ifeng.com/app/hq/stock/{0}/", sharesCode);
            string htmlContent = RequestHelp.Get(url, Encoding.GetEncoding("UTF-8"));
            return ConvertToObj(htmlContent);
        }

        /// </summary>
        /// <param name="Content"></param>
        /// <returns></returns>
        public static TradeExtensionsData ConvertToObj(string Content)
        {

            TradeExtensionsData transData = new TradeExtensionsData();
            if (string.IsNullOrWhiteSpace(Content))
                return transData;
            Regex reg_Content = new Regex(@".*?hq_str.*?(\d+)=""(.*?)""", RegexOptions.IgnoreCase);
            if (!reg_Content.IsMatch(Content))
                return transData;
            var m = reg_Content.Match(Content);
            return transData;
        }
    }
}
